//
//  GYBtnView.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/10.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYBtnView.h"
#import "Head.h"
@interface GYBtnView ()
@property(nonatomic,strong)UILabel* titleLab;
@property(nonatomic,strong)UIImageView* titleIV;
@property(nonatomic,strong)UILabel* countLab;
@property(nonatomic,strong)NSString* countstr;
@end
@implementation GYBtnView

-(UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab=[[UILabel alloc] init];
        _titleLab.textColor=Main_Color_LightGray;
        _titleLab.font=SYSTEMFONT(11);
        _titleLab.textAlignment=NSTextAlignmentCenter;
    }
    return _titleLab;
}

-(UILabel *)countLab
{
    if (!_countLab) {
        _countLab=[[UILabel alloc] init];
        _countLab.textColor=[UIColor whiteColor];
        _countLab.font=SYSTEMFONT(14);
        _countLab.backgroundColor=Main_Color_Red;
        _countLab.textAlignment=NSTextAlignmentCenter;
    }
    return _countLab;
}

-(UIImageView *)titleIV
{
    if (!_titleIV) {
        _titleIV=[[UIImageView alloc] init];
    }
    return _titleIV;
}

-(instancetype)initWithFrame:(CGRect)frame titleStr:(NSString *)title image:(NSString *)imageStr count:(NSString *)count
{
    self=[super initWithFrame:frame];
    if (self)
    {
        self.userInteractionEnabled=YES;
         self.titleLab.frame=CGRectMake(0, self.height-17, self.width, 15);
        self.titleLab.text=title;
         self.titleIV.image=[UIImage imageNamed:imageStr];
         self.titleIV.frame=CGRectMake((self.width-_titleIV.image.size.width)/2, 7, _titleIV.image.size.width, _titleIV.image.size.height);
        _countstr=count;
        [self addSubview:self.titleIV];
        [self addSubview:self.titleLab];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    if (![WFFunctions WFStrCheckEmpty:_countstr]) {
        self.countLab.frame=CGRectMake(self.width-20, 0, 20, 20);
        self.countLab.text=_countstr;
        [WFFunctions WFUIaddbordertoView:self.countLab radius:10 width:0 color:[UIColor clearColor]];
        [self addSubview:self.countLab];
    }else
    {
        self.countLab.frame=CGRectZero;
        self.countLab.text=@"";
    }
}
-(void)setBtnImage:(NSString *)image
{
    self.titleIV.image=[UIImage imageNamed:image];
}
-(void)setCountLabHHH:(NSString *)count
{
    _countstr=count;
    [self layoutSubviews];
}


@end
